﻿using System.Windows;
using ScrumManagementTool.domain.interfaces;
using ScrumManagementTool.service;

namespace ScrumManagementToolUserControls
{
    /// <summary>
    /// Interaction logic for NewProject.xaml
    /// </summary>
    public partial class NewProject
    {
        private MainWindow parentWindow;
        private ProjectService projectService = new ProjectService();

        public NewProject()
        {
            InitializeComponent();
        }

        private void btnCreateProject_Click(object sender, RoutedEventArgs e)
        {
            IProject project = projectService.CreateNewProject(txtProjectName.Text);
            parentWindow = GetTopParent() as MainWindow;
            parentWindow.projectTree.BuildTree(project);
            txtProjectName.Text = "";
            Visibility = Visibility.Collapsed;
        }

        private void btnCancelProject_Click(object sender, RoutedEventArgs e)
        {
            txtProjectName.Text = "";
            Visibility = Visibility.Collapsed;
        }

        private Window GetTopParent()
        {
            DependencyObject dpParent = Parent;
            do
            {
                dpParent = LogicalTreeHelper.GetParent(dpParent);
            } while (dpParent.GetType().BaseType != typeof(Window));
            return dpParent as Window;
        }
    }
}
